#include "zygtray.h"

ZygTrayIcon::ZygTrayIcon(QMainWindow* parentWidget): QSystemTrayIcon (){
    this->parentWidget = parentWidget;
    QIcon ico(":/resource/images/zyg.ico");
    this->setIcon(ico);
    this->setToolTip("张余歌clock");

    // 设置托盘菜单
    this->zygTrayMenu = new QMenu();
    QAction* exitAction = new QAction("张余歌下班",this->zygTrayMenu);
    this->zygTrayMenu->addAction(exitAction);
    connect(exitAction,&QAction::triggered,this->parentWidget,&QApplication::exit);

    // 退出被点击
    connect(this,&QSystemTrayIcon::activated,[=](QSystemTrayIcon::ActivationReason reason){
        switch (reason) {
            case QSystemTrayIcon::DoubleClick:
                this->parentWidget->show();
                break;
            default:
                break;

        }
    });

    this->setContextMenu(this->zygTrayMenu);
    this->show();
}

ZygTrayIcon::~ZygTrayIcon(){

}

void ZygTrayIcon::on_exit(){
    qDebug() << "退出程序";
}
